<template>
  <!-- 对话框(添加 / 修改) -->
  <el-dialog
    :title="title"
    :visible.sync="show"
    width="800px"
    append-to-body
    :before-close="cancel"
    :close-on-click-modal="false"
  >
    <el-row>
      <div class="group-name">基本信息</div>

      <el-col class="item" :span="12">所属学院:{{ form.collegeName }}</el-col>
      <el-col class="item" :span="12"
        >所属系部:{{ form.departmentName }}</el-col
      >
      <el-col class="item" :span="12">班级:{{ form.className }}</el-col>
      <el-col class="item" :span="12">姓名:{{ form.clockUserName }}</el-col>
      <el-col class="item" :span="12">基准打卡:{{ form.standardTime }}</el-col>
      <el-col class="item" :span="12"
        >打卡时间:{{ parseTime(form.clockTime) }}</el-col
      >
      <el-col class="item" :span="12"
        >打卡结果
        <dict-tag
          :type="DICT_TYPE.ACCOMMODATION_CLOCK_STATUS"
          :value="form.clockStatus"
        />
      </el-col>
      <!-- <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                  <el-form-item label="上课时间ID" prop="studyTimeId">
                    <el-input v-model="form.studyTimeId" placeholder="请选择上课时间ID"/>
                  </el-form-item>
                      <el-form-item label="星期" prop="weekId">
                        <el-input v-model="form.weekId" placeholder="请输入星期" />
                      </el-form-item>
                      <el-form-item label="班级ID" prop="classesId">
                        <el-input v-model="form.classesId" placeholder="请输入班级ID" />
                      </el-form-item>
                      <el-form-item label="课程ID" prop="subjectId">
                        <el-input v-model="form.subjectId" placeholder="请输入课程ID" />
                      </el-form-item>
                      <el-form-item label="教室信息" prop="roomId">
                        <el-input v-model="form.roomId" placeholder="请输入教室信息" />
                      </el-form-item>
                  <el-form-item label="打卡时间" prop="clockTime">
                    <el-date-picker clearable v-model="form.clockTime" type="date" value-format="timestamp" placeholder="选择打卡时间" />
                  </el-form-item>
                  <el-form-item label="打卡类型" prop="clockType">
                    <el-select v-model="form.clockType" placeholder="请选择打卡类型">
                          <el-option v-for="dict in this.getDictDatas(DICT_TYPE.CLASS_CLOCK_TYPE)"
                                     :key="dict.value" :label="dict.label" :value="dict.value" />
                    </el-select>
                  </el-form-item>
                      <el-form-item label="教师信息" prop="teacherId">
                        <el-input v-model="form.teacherId" placeholder="请输入教师信息" />
                      </el-form-item>
                      <el-form-item label="打卡备注" prop="clockRemark">
                        <el-input v-model="form.clockRemark" placeholder="请输入打卡备注" />
                      </el-form-item>
                      <el-form-item label="备注" prop="remark">
                        <el-input v-model="form.remark" placeholder="请输入备注" />
                      </el-form-item>
    </el-form> -->
      <!-- <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div> -->
    </el-row>
  </el-dialog>
</template>

<script>
import { createClockRecord, updateClockRecord } from "@/api/study/clockRecord";

export default {
  name: "ClockRecordEdit",
  components: {
  },
  data() {
    return {
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        studyTimeId: [{ required: true, message: "上课时间ID不能为空", trigger: "change" }],
        weekId: [{ required: true, message: "星期不能为空", trigger: "blur" }],
      }
    };
  },
  created() { },
  props: {
    // 是否显示弹出层
    show: {
      type: Boolean,
      default: false
    },
    // 显示弹出层标题
    title: {
      type: String,
      default: ''
    }
  },
  methods: {
    /** 初始化编辑的数据**/
    initData(rowData) {
      this.reset();
      if (rowData && rowData.id) {
        this.form = rowData;
        this.form.datetimerange = [this.form.startTime, this.form.endTime]
      }
    },
    /** 取消按钮 */
    cancel() {
      this.$emit('update:show', false)
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        studyTimeId: undefined,
        weekId: undefined,
        classesId: undefined,
        subjectId: undefined,
        roomId: undefined,
        clockTime: undefined,
        clockType: undefined,
        teacherId: undefined,
        clockRemark: undefined,
        remark: undefined,
      };
      this.resetForm("form");
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (!valid) {
          return;
        }
        // 修改的提交
        if (this.form.id != null) {
          updateClockRecord(this.form).then(response => {
            this.$modal.msgSuccess("修改成功");
            this.cancel();
            this.$emit('success')
          });
          return;
        }
        // 添加的提交
        createClockRecord(this.form).then(response => {
          this.$modal.msgSuccess("新增成功");
          this.cancel();
          this.$emit('success')
        });
      });
    },

  }
};
</script>
<style scoped>
.group-name {
  padding: 10px;
  border-bottom: 1px solid #f5f5f5;
  margin-bottom: 20px;
  font-size: 16px;
  font-weight: bold;
}
.item {
  margin: 10px 0;
}
</style>
